package com.clk.portfoy.complib.portfoy.takip;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JScrollPane;
import javax.swing.border.EtchedBorder;

import com.clk.desktop.gui.components.basic.ClkButton;
import com.clk.desktop.gui.components.basic.ClkLabel;
import com.clk.desktop.gui.components.basic.ClkPanel;
import com.clk.desktop.gui.components.basic.ClkTextField;
import com.clk.portfoy.PortfoyStatics;
import com.clk.portfoy.classlib.portfoy.InfPortfoyObserver;
import com.clk.portfoy.classlib.portfoy.Portfoy;
import com.clk.portfoy.complib.ClkDegerLabel;
import com.clk.portfoy.complib.ClkKZLabel;

public class ClkPortfoyTakipPanel extends ClkPanel implements InfPortfoyObserver {

	private class BtnRefreshActionListener implements ActionListener {
		public void actionPerformed(final ActionEvent e) {
			do_btnRefresh_actionPerformed(e);
		}
	}

	private ClkButton btnRefresh;
	private ClkKZLabel lblAnlikKZDeger;
	private ClkDegerLabel lblPortfoyDeger;
	private ClkLabel lblRefreshTime;
	private ClkLabel lblSonuc;
	private ClkLabel lblSonucKZ;
	private ClkTextField txtSonucKZ;
	private ClkTextField txtSonuc;
	private JScrollPane scrollPane;
	private ClkLabel lblHedef;
	private ClkLabel lblHedefKZ;
	private ClkTextField txtHedefKZ;
	private ClkTextField txtHedef;
	private ClkLabel lblDeger;
	private ClkLabel lblAnlikKZ;
	private ClkTextField txtMaliyet;
	private ClkLabel lblMaliyet;
	private ClkPanel clkPanel;
	private ClkPortfoyTakipTable tblPortfoy;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Portfoy portfoy;

	// ---------------------------------------------------------------------------------
	public ClkPortfoyTakipPanel() {
		super();
		initGUI();
		btnRefresh.setIcon(PortfoyStatics.imgRefresh);
		txtHedef.setHorizontalAlignment(ClkTextField.RIGHT);
		txtHedefKZ.setHorizontalAlignment(ClkTextField.RIGHT);
		txtMaliyet.setHorizontalAlignment(ClkTextField.RIGHT);
		txtSonuc.setHorizontalAlignment(ClkTextField.RIGHT);
		txtSonucKZ.setHorizontalAlignment(ClkTextField.RIGHT);
	}

	// ---------------------------------------------------------------------------------
	private void initGUI() {
		setLayout(null);
		setBorder(new EtchedBorder(EtchedBorder.LOWERED));
		{
			clkPanel = new ClkPanel();
			clkPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
			clkPanel.setLayout(null);
			clkPanel.setBounds(433, 10, 204, 189);
			add(clkPanel);
			{
				lblMaliyet = new ClkLabel();
				lblMaliyet.setBounds(10, 10, 81, 20);
				lblMaliyet.setText("Maliyet");
				clkPanel.add(lblMaliyet);
			}
			{
				txtMaliyet = new ClkTextField();
				txtMaliyet.setBounds(97, 10, 99, 20);
				clkPanel.add(txtMaliyet);
			}
			{
				lblAnlikKZ = new ClkLabel();
				lblAnlikKZ.setText("AnlikKarZarar");
				lblAnlikKZ.setBounds(10, 61, 99, 20);
				clkPanel.add(lblAnlikKZ);
			}
			{
				lblDeger = new ClkLabel();
				lblDeger.setText("AnlikDeger");
				lblDeger.setBounds(10, 36, 81, 20);
				clkPanel.add(lblDeger);
			}
			{
				txtHedef = new ClkTextField();
				txtHedef.setBounds(97, 87, 99, 20);
				clkPanel.add(txtHedef);
			}
			{
				txtHedefKZ = new ClkTextField();
				txtHedefKZ.setBounds(115, 112, 81, 20);
				clkPanel.add(txtHedefKZ);
			}
			{
				lblHedefKZ = new ClkLabel();
				lblHedefKZ.setText("HedefKarZarar");
				lblHedefKZ.setBounds(10, 112, 99, 20);
				clkPanel.add(lblHedefKZ);
			}
			{
				lblHedef = new ClkLabel();
				lblHedef.setText("HedefDeger");
				lblHedef.setBounds(10, 87, 81, 20);
				clkPanel.add(lblHedef);
			}
			{
				txtSonuc = new ClkTextField();
				txtSonuc.setBounds(97, 138, 99, 20);
				clkPanel.add(txtSonuc);
			}
			{
				txtSonucKZ = new ClkTextField();
				txtSonucKZ.setBounds(115, 163, 81, 20);
				clkPanel.add(txtSonucKZ);
			}
			{
				lblSonucKZ = new ClkLabel();
				lblSonucKZ.setText("SonucKarZarar");
				lblSonucKZ.setBounds(10, 163, 99, 20);
				clkPanel.add(lblSonucKZ);
			}
			{
				lblSonuc = new ClkLabel();
				lblSonuc.setText("SonucDeger");
				lblSonuc.setBounds(10, 138, 81, 20);
				clkPanel.add(lblSonuc);
			}
			{
				lblPortfoyDeger = new ClkDegerLabel();
				lblPortfoyDeger.setBounds(97, 36, 99, 20);
				clkPanel.add(lblPortfoyDeger);
			}
			{
				lblAnlikKZDeger = new ClkKZLabel();
				lblAnlikKZDeger.setBounds(115, 61, 81, 20);
				clkPanel.add(lblAnlikKZDeger);
			}
		}
		{
			scrollPane = new JScrollPane();
			scrollPane.setBounds(10, 10, 417, 189);
			add(scrollPane);
			{
				tblPortfoy = new ClkPortfoyTakipTable();
				scrollPane.setViewportView(tblPortfoy);
			}
		}
		{
			btnRefresh = new ClkButton();
			btnRefresh.addActionListener(new BtnRefreshActionListener());
			btnRefresh.setBounds(643, 134, 88, 65);
			add(btnRefresh);
		}
		{
			lblRefreshTime = new ClkLabel();
			lblRefreshTime.setBounds(643, 108, 88, 20);
			add(lblRefreshTime);
		}
	}

	// ---------------------------------------------------------------------------------
	public void refresh() {
		lblRefreshTime.setText(PortfoyStatics.getTimeStr(portfoy.getRefreshDate()));
		lblAnlikKZDeger.setText(portfoy.getStrPotKZ());
		txtHedef.setText(portfoy.getStrHedefDeger());
		txtHedefKZ.setText(portfoy.getStrHedefPotKZ());
		txtMaliyet.setText(portfoy.getStrAlisDeger());
		txtSonuc.setText(portfoy.getStrRealizeDeger());
		txtSonucKZ.setText(portfoy.getStrRealizeKZ());
		tblPortfoy.setPortfoy(portfoy);
		lblPortfoyDeger.setValue(portfoy.getAnlikDegerSet());
	}

	// ---------------------------------------------------------------------------------
	@Override
	public void notifyObs(Portfoy p) {
		// TODO Auto-generated method stub
		this.portfoy = p;
		this.refresh();
	}

	// ---------------------------------------------------------------------------------
	protected void do_btnRefresh_actionPerformed(final ActionEvent e) {
		this.portfoy.refresh();
	}
	// ---------------------------------------------------------------------------------
}
